package com.example.zhengchaojun.arcgis.basicesTest.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.TextView;

import com.esri.arcgisruntime.layers.Layer;
import com.example.zhengchaojun.arcgis.R;
import com.example.zhengchaojun.arcgis.baseadapter.ListViewBaseAdapter;

import java.util.List;

/**
 * 类描述：图层管理
 * 作者：郑朝军 on 2018/5/31
 * 邮箱：1250393285@qq.com
 * 公司：武汉智博创享科技有限公司
 * 修改人：郑朝军 on 2018/5/31
 * 修改备注：
 */
public class LayerListviewAdapter extends ListViewBaseAdapter<Layer>
{
    public LayerListviewAdapter(Activity activity, List<Layer> list)
    {
        super(activity, list);
    }

    public View getView(final int position, View convertView, ViewGroup parent)
    {
        convertView = getItemView(convertView, R.layout.widget_view_layer_managet_layers_item, parent);
        final CheckBox checkBox = getView(convertView, R.id.widget_view_layer_managet_item_cbxLayer);
        final SeekBar seekBar = getView(convertView, R.id.opactiy_element_layout_layerOpactiySeekBar);
        final TextView textView = getView(convertView, R.id.tv_text);

        final Layer layer = getItem(position);

        checkBox.setText(layer.getName());
        checkBox.setChecked(layer.isVisible());//设置是否显示

        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
        {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                if (isChecked)
                {
                    layer.setVisible(true);
                }
                else
                {
                    layer.setVisible(false);
                }
            }
        });

        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
        {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
            {
                float op = (float) progress / 100;
                textView.setText("透明度:" + String.valueOf(op));
                layer.setOpacity(op);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar)
            {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar)
            {

            }
        });
        return convertView;
    }
}
